package com.lire.shop.service.impl;

import com.lire.shop.dao.ProductRepository;
import com.lire.shop.data.NullObjects;
import com.lire.shop.entity.Product;
import com.lire.shop.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductRepository productRepository;

   public Product getProductById(Long pid){
       return productRepository
               .findById(pid)
               .orElseGet(NullObjects::getProduct);
    }

    @Override
    public void updateStock(Product product) {
       productRepository.updateStockByPid(product.getStock(),product.getPid());
    }

}
